﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Ccit.Utils;
using System.Text;
using System.Collections.Generic;
using Newtonsoft.Json;
using Ccit.OA.MsSystemDoc;

namespace Ccit.OA.SystemDoc
{
    public partial class SystemDoc_docmanage_query : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {

                hidFolderId.Value = (null != Request.QueryString["folderId"]) ? Request.QueryString["folderId"].ToString() : "0";
                hidClassType.Value = (null != Request.QueryString["classType"]) ? Request.QueryString["classType"].ToString() : "001";
                pageinit();
            }
        }

        private void pageinit()
        {
            
            string sWhere,sFolderId,sClassType,sShare;
            sFolderId = hidFolderId.Value.Trim(); ;
            sClassType = hidClassType.Value.Trim();
            if (sFolderId != "0")
            {
                sWhere = " and DOC_B2_90 = '" + sClassType + "' ";
            }
            else {
                sWhere = " and DOC_B2_40 IN(" + sFolderId + ") and DOC_B2_90 = '" + sClassType + "' ";
            }
            

            SystemDocBLL Bll = new SystemDocBLL();
            List<MsSecondClass> msList = Bll.GetMsSecondItem(sWhere);
            if (msList.Count != 0)
            {
                ddFolder.ClearSelection();
                ListItem List = new ListItem();
                List.Text =  Bll.GetSysDocNode(sClassType,"");
                List.Value = "0_05";
                ddFolder.Items.Add(List);
                for (int i = 0; i < msList.Count; i++)
                {
                    sShare = Bll.GetShare(msList[i].Sysdocid);
                    List = new ListItem();
                    List.Text = HttpUtility.HtmlDecode("&nbsp;&nbsp;") + msList[i].Systypename;
                    List.Value = msList[i].Sysdocid + "_" + sShare;

                    ddFolder.Items.Add(List);
                    DDBind(msList[i].Sysdocid, sClassType, "&nbsp;&nbsp;", sShare);
                }
            }
           
            for (int i = 0; i < 5; i++)
            {
                this.rbDatetime.Items[i].Attributes.Add("onclick", "rbDate()");
                this.rbsize.Items[i].Attributes.Add("onclick", "rbSize()");
            }
            txtsizezd.Attributes.Add("onKeyDown", "CliNumber('txtsizezd')");
            btsearch.Attributes.Add("onclick", "return  doSearch()");

            Bll = null;
            msList = null;
        }

        public void DDBind(string Superiorid, string classType, string sbEmpty,string sParaShare)
        {
            string sWhere,  sFolderId,sShare;
            sFolderId = hidFolderId.Value.Trim();
            sbEmpty += "&nbsp;&nbsp;";
            sWhere = " and DOC_B2_40 IN(" + Superiorid + ") and DOC_B2_90 = '" + classType + "' ";
            SystemDocBLL Bll = new SystemDocBLL();
            List<MsSecondClass> msList = Bll.GetMsSecondItem(sWhere);
            
            if (msList.Count != 0)
            {
              
                for (int i = 0; i < msList.Count; i++)
                {
                    if (sParaShare == "01" || sParaShare == "00")
                    {
                        sShare = sParaShare;
                    }
                    else { 
                        sShare = Bll.GetShare(msList[i].Sysdocid);
                    }
                        
                    ListItem List = new ListItem();
                    List.Text = HttpUtility.HtmlDecode(sbEmpty) + msList[i].Systypename;
                    List.Value = msList[i].Sysdocid + "_" + sShare;

                    ddFolder.Items.Add(List);
                    DDBind(msList[i].Sysdocid, classType, sbEmpty, sShare);
                }
            }
            Bll = null;
            msList = null;
        }
    }
}
